package com.zrwl.poscloud.core.task.file;

import com.zrwl.poscloud.xo.service.FileInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import org.springframework.scheduling.support.CronTrigger;
import org.springframework.stereotype.Component;

@Component
public class FileDeleteTask implements SchedulingConfigurer {

    @Autowired
    private FileInfoService fileInfoService;

    @Override
    public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
        taskRegistrar.addTriggerTask(() -> {
            fileInfoService.deleteFilesFromDisk();
        }, triggerContext -> {
            //任务触发、可修改任务的执行周期
            String CRON = "0 0 2 * * ?";//cron表达式 每天2点整触发
            CronTrigger trigger = new CronTrigger(CRON);
            return trigger.nextExecutionTime(triggerContext);
        });
    }
}

